package com.tedu.project5.controller;


import com.tedu.project5.common.Result;
import com.tedu.project5.dto.PermissionDTO;
import com.tedu.project5.dto.QueryPermissionDTO;
import com.tedu.project5.model.DdPermission;
import com.tedu.project5.service.IDdPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mhg
 * @since 2022-06-13
 */
@Slf4j
@RestController
@RequestMapping("/project5/ddPermission")
public class DdPermissionController {

    @Autowired
    private IDdPermissionService iDdPermissionService;

    /**
     * 查询权限列表
     * @return
     * http://localhost:9999/project5/ddPermission/listAll
     */
    @CrossOrigin
    @PostMapping("/listAll")
    public Result list(@RequestBody QueryPermissionDTO dto){
        log.info("参数值--:"+ dto);
        return iDdPermissionService.queryExample(dto);
    }

    /**
     * 新增权限
     * @param permission
     * @return
     */
    @CrossOrigin
    @PostMapping("/addPermission")
    public Result addUser(@RequestBody DdPermission permission){
        log.info("参数值--："+ permission);
        return iDdPermissionService.savePermission(permission);
    }

    /**
     * 更新权限信息
     * @param dto
     * @return
     */
    @CrossOrigin
    @PostMapping("/updateById")
    public Result updateById(@RequestBody PermissionDTO dto){
        log.info("参数值--："+ dto);
        return iDdPermissionService.updatePermission(dto);
    }

    /**
     * 删除权限信息
     * @param id
     * @return
     */
    @CrossOrigin
    @PostMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable String id){
        log.info("参数值id--："+ id);
        return iDdPermissionService.deletePermission(id);
    }
    
}
